package com.tupi.project.http.component;

import java.io.IOException;

import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 封装公共参数（Key和密码）
 * <p>
 */
public class CommonInterceptor implements Interceptor
{

    @Override
    public Response intercept(Interceptor.Chain chain) throws IOException
    {
        Request oldRequest = chain.request();

        // 添加新的参数
        HttpUrl.Builder authorizedUrlBuilder = oldRequest.url().newBuilder().scheme(oldRequest
                .url().scheme()).host(oldRequest.url().host());
//                .addQueryParameter(Constants.TOKEN,
//                BaseInfo.TOKEN).addQueryParameter(Constants.DEVICE_NUM, BaseInfo.PHONE_IMEI)
//                .addQueryParameter(Constants.DEVICE_NAME, BaseInfo.PHONE_MANUFACTURER + BaseInfo
//                        .PHONE_MODEL).addQueryParameter(Constants.DEVICE_VERSION, BaseInfo
//                        .PHONE_SYSTEM_VERSION).addQueryParameter(Constants.MAC, BaseInfo
//                        .ADDRESS_MAC).addQueryParameter(Constants.SCREEN_SIZE, BaseInfo
//                        .SCREEN_SIZE + ":" + BaseInfo.WIDTH_PIXELS + ":" + BaseInfo
//                        .HEIGHT_PIXELS).addQueryParameter(Constants.CLIENT_VERSION, BaseInfo
//                        .VERSION_NAME + "");

        // 新的请求
        Request newRequest = oldRequest.newBuilder().method(oldRequest.method(), oldRequest.body
                ()).url(authorizedUrlBuilder.build()).build();

        return chain.proceed(newRequest);
    }
}